package org.example.annation;


import org.example.util.IdValidateUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 用来定义自定义注解和验证信息IdValidateUtils的绑定
 */
public class IdValidateConstraintValidator implements ConstraintValidator<UIdValidation, Object> {
    @Override
    public void initialize(UIdValidation constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    /**
     * 此方法是对于接受到的o对象进行判断，是否满足于对应的id的操作，如果不满足就提示对应的msg信息
     *
     * @param o 我们传入的哪个字符串
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        return IdValidateUtils.isIdNumberValidated(o.toString());
    }
}
